<template>
	<view class="wx-index">
		<view v-if="page_is_show">
			<image class="wx-bg" src="../../static/downbg.png" mode="aspectFill"></image>
			<view class="wx-btn">
				<view class="bttitle">{{web_name}}</view>
				<view @click="download" class="btn">立即下载</view>
				<view class="version">当前版本v{{version}}</view>
			</view>
		</view>
	</view>
</template>
<script>
	var app = getApp();// 兼容
	export default {
		data() {
			return {
				page_is_show: false,
				web_name: '',
				web_logo: '',
				url: '',
				version: ''
			}
		},
		onLoad() {
			var self = this;
			uni.showLoading({
				title: '加载中'
			})
            var userAgent = window.navigator.userAgent.toLowerCase();
            if (userAgent.match(/MicroMessenger/i) == 'micromessenger') {
                uni.showModal({
                    showCancel: false,
                    title: "提示",
                    content: "请用外部浏览器打开！"
                });
            }
            //页面初始化进入app，进不去就说明没安装app，然后可以点击下载去应用市场去下载
			if (userAgent.match(/(iphone|ipod|ipad);?/i)) {
			     console.log('iphone');
				//window.location.href = "";
			} else if (userAgent.match(/android/i)) {
			     console.log('android');
				window.location.href = "imchat-tengyun://";  //manifest.json配置的schemes
			}
			self.reloadconfig();
			self.getVersion();
		},
		methods: {
			reloadconfig(){
				var self = this;
				if(this.$fc.is_empty(app.globalData.appconfig)){
					setTimeout(()=>{
						self.reloadconfig();
					},500);
				}else{
					self.page_is_show = true;
					self.web_name = app.globalData.appconfig.web_name;
					uni.hideLoading();
				}
			},
		    getVersion(){
				var self = this;
				self.$http.request({
					url: '/common/getVersion',
					success: (res) => {
						if(res.data.code == 200){
							self.version = res.data.data.version;
							self.url = res.data.data.url;
						}
					}
				});
		    },
			download(){
				var self = this;
				if(self.url){
                    window.location.href=self.url;
				}else{
					uni.showToast({
						title: '再无下载通道',
						icon: 'none',
						position: 'bottom'
					})
				}
			}
		}
	}
</script>
<style scoped>
	.wx-index{
		width: 100vw;
		height: 100vh;
		overflow: hidden;
		position: relative;
	}
	.wx-bg{
		width: 100vw;
		height: 100vh;
	}
	.wx-btn{
		position: absolute;
		bottom: 100rpx;
		left: 0;
		width: 100%;
		text-align: center;
	}
	.wx-btn .bttitle{
		font-size: 60rpx;
		color: #05C160;
	}
	.wx-btn .btn{
		margin-top: 40px;
		width: 50%;
		margin-left: 25%;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		color: #ffffff;
		background: #05C160;
		border-radius: 20rpx;
		font-size: 36rpx;
	}
	.wx-btn .version{
		color: #000000;
		height: 40px;
		line-height: 40px;
		font-size: 28rpx;
	}
</style>
